/**
 * 
 */
package com.sft.test;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import java.util.Set;

import org.apache.log4j.Logger;
import org.junit.Test;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisShardInfo;

/**
 * @author sft
 *
 *         2016年4月22日
 */
public class JedisOpr {
	private static final Logger log=Logger.getLogger(JedisOpr.class);
	
	
	/**
	 * 操作String
	 */
	@SuppressWarnings("resource")
	@Test
	public void redisString() {
		JedisShardInfo jsi=new JedisShardInfo("192.168.2.93", 6379);
		jsi.setPassword("sftadmin");
		Jedis jedis=new Jedis(jsi);
		log.info("db"+jsi.getDb());
		jedis.set("aa", "fasdfq1");
		String str=jedis.get("aa");
		log.info(str);
	}
	
	
	/**
	 * 操作List
	 */
	@SuppressWarnings("resource")
	@Test
	public void redisList() {
		JedisShardInfo jsi=new JedisShardInfo("192.168.2.93", 6379);
		jsi.setPassword("sftadmin");
		Jedis jedis=new Jedis(jsi);
		
		String[] strs={"lfasdf1","ldsfist2dsaf","lidsfasst3"};
		jedis.lpush("list", strs);
		List<String> strs1=jedis.lrange("list",0,20);
		log.info(strs1.size());
	}
	
	
	/**
	 * 操作key
	 */
	@SuppressWarnings("resource")
	@Test
	public void redisKey() {
		JedisShardInfo jsi=new JedisShardInfo("192.168.2.93", 6379);
		jsi.setPassword("sftadmin");
		Jedis jedis=new Jedis(jsi);
	    
	}
	
	
	/**
	 * URI方式连接
	 * 操作String
	 * @throws URISyntaxException 
	 */
	@SuppressWarnings("resource")
	@Test
	public void redisStringURI() throws URISyntaxException {
		JedisShardInfo jsi=new JedisShardInfo(new URI("redis://:sftadmin@192.168.2.93:6379/3"));
		jsi.setPassword("sftadmin");
		Jedis jedis=new Jedis(jsi);
		log.info("db"+jsi.getDb());
		jedis.set("aa", "db3");
		String str=jedis.get("aa");
		log.info(str);
	}
}
